package com.ruoyi.system.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.domain.HmzProduct;
import com.ruoyi.system.service.IHmzProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.HmzStorageRequestDetailMapper;
import com.ruoyi.system.domain.HmzStorageRequestDetail;
import com.ruoyi.system.service.IHmzStorageRequestDetailService;

/**
 * 用于存储入库申请明细信息的Service业务层处理
 *
 * @author ruoyi
 * @date 2023-11-10
 */
@Service
public class HmzStorageRequestDetailServiceImpl implements IHmzStorageRequestDetailService
{
    @Autowired
    private HmzStorageRequestDetailMapper hmzStorageRequestDetailMapper;
    @Autowired
    private IHmzProductService hmzProductService;
    /**
     * 查询用于存储入库申请明细信息的
     *
     * @param id 用于存储入库申请明细信息的主键
     * @return 用于存储入库申请明细信息的
     */
    @Override
    public HmzStorageRequestDetail selectHmzStorageRequestDetailById(Long id)
    {
        return hmzStorageRequestDetailMapper.selectHmzStorageRequestDetailById(id);
    }

    /**
     * 查询用于存储入库申请明细信息的列表
     *
     * @param hmzStorageRequestDetail 用于存储入库申请明细信息的
     * @return 用于存储入库申请明细信息的
     */
    @Override
    public List<HmzStorageRequestDetail> selectHmzStorageRequestDetailList(HmzStorageRequestDetail hmzStorageRequestDetail)
    {
        List<HmzStorageRequestDetail> hmzStorageRequestDetails = hmzStorageRequestDetailMapper.selectHmzStorageRequestDetailList(hmzStorageRequestDetail);
        if(hmzStorageRequestDetails !=null && hmzStorageRequestDetails.size() > 0){
            for (HmzStorageRequestDetail storageRequestDetail : hmzStorageRequestDetails) {

                Long productId = storageRequestDetail.getProductId();
                HmzProduct hmzProduct = hmzProductService.selectHmzProductById(productId);
                storageRequestDetail.setInfo(hmzProduct);
            }
        }
        return hmzStorageRequestDetails;
    }

    /**
     * 新增用于存储入库申请明细信息的
     *
     * @param hmzStorageRequestDetail 用于存储入库申请明细信息的
     * @return 结果
     */
    @Override
    public int insertHmzStorageRequestDetail(HmzStorageRequestDetail hmzStorageRequestDetail)
    {
        hmzStorageRequestDetail.setCreateTime(DateUtils.getNowDate());
        return hmzStorageRequestDetailMapper.insertHmzStorageRequestDetail(hmzStorageRequestDetail);
    }

    /**
     * 修改用于存储入库申请明细信息的
     *
     * @param hmzStorageRequestDetail 用于存储入库申请明细信息的
     * @return 结果
     */
    @Override
    public int updateHmzStorageRequestDetail(HmzStorageRequestDetail hmzStorageRequestDetail)
    {
        hmzStorageRequestDetail.setUpdateTime(DateUtils.getNowDate());
        return hmzStorageRequestDetailMapper.updateHmzStorageRequestDetail(hmzStorageRequestDetail);
    }

    /**
     * 批量删除用于存储入库申请明细信息的
     *
     * @param ids 需要删除的用于存储入库申请明细信息的主键
     * @return 结果
     */
    @Override
    public int deleteHmzStorageRequestDetailByIds(Long[] ids)
    {
        return hmzStorageRequestDetailMapper.deleteHmzStorageRequestDetailByIds(ids);
    }

    /**
     * 删除用于存储入库申请明细信息的信息
     *
     * @param id 用于存储入库申请明细信息的主键
     * @return 结果
     */
    @Override
    public int deleteHmzStorageRequestDetailById(Long id)
    {
        return hmzStorageRequestDetailMapper.deleteHmzStorageRequestDetailById(id);
    }
}
